<template>
  <div class="common-page">
    <div class="header">
      <div class="title">企业审核列表</div>
    </div>
    <SearchForm
      :search-list="searchList"
      :search-params="searchParams"
      @search="onSearch"
      @reset="onReset"
    />
    <div class="table-box">
      <el-table
        v-loading="loading"
        height="100%"
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >

        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
        <el-table-column label="操作" fixed="right" width="220px">
          <template slot-scope="scope">
            <el-button type="primary" @click="onUpdateStatus(1, scope.row)">通过</el-button>
            <el-button type="danger" @click="onUpdateStatus2(scope.row)">拒绝</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
    <Add ref="addFormRef" />
      <el-dialog
          title="审核拒绝"
          :visible.sync="dialogValue"
          width="500px"
          append-to-body
      >
          <SubmitForm
              :rule-form="ruleForm"
              :rules="rules"
              :form-list="formList"
              @close="dialogValue = false"
              @save="onSave"
          />
      </el-dialog>

  </div>
</template>

<script>
import crud from '@/mixins/crud'
import Add from './add'
import { http } from '@/api'
import { getName, Investor, ProjectType } from '@/dict'
export default {
  name: 'Index',
  components: {
    Add
  },
  mixins: [crud],
  data() {
    return {
      request: {
        page: http.enterprise.auditPage,
        updateStatus: http.enterprise.updateStatus
      },
      searchList: [
        {
          key: 'enterpriseType',
          name: 'select',
          label: '企业类型',
          options: [
          ]
        },
        {
          key: 'enterpriseName',
          name: 'input',
          label: '企业名称'
        }
      ],
      searchParams: {
        enterpriseName: '',
        enterpriseType: ''
      },
      columns: [
        { prop: 'enterpriseName', label: '企业名称' },
        { prop: 'enterpriseTypeName', label: '企业类型' },
        { prop: 'createTime', label: '上传时间' }
      ],
      tableData: [

      ],
    
        ruleForm: {
            refusalCause: '',
        },
        rules: {
            refusalCause: [{ required: true, message: '不能为空' }]
        },
        formList: [
            {
                key: 'refusalCause',
                name: 'input',
                label: '原因',
                type: 'textarea',
                colSpan: 24
            },
        ]
    }
  },
  created() {
    http.enterprise.categoryList().then(res => {
      this.searchList[0].options = res.data.map(el => {
        return {
          value: el,
          name: el
        }
      })
    })
  },
  methods: {
    formatTableData(data) {
      data.forEach(el => {
        el.enterpriseTypeName = getName(el.enterpriseType, this.searchList[0].options)
      })
    },
      onUpdateStatus2(row) {
        this.currentDetail = row
          this.dialogValue = true
      },
      onSave() {
        this.request.updateStatus({
            id: this.currentDetail.id,
            state: 2,
            refusalCause: this.ruleForm.refusalCause
        }).then(res => {
            this.$message.success(res.msg)
            this.dialogValue = false
            this.ruleForm.refusalCause = ''
            this.initData()
        })
      }
  }
}
</script>

<style scoped lang="scss">
</style>
